package com.bhs.sansonglogistics.ui.adapter;

import android.text.Html;
import android.text.Spanned;
import android.text.TextUtils;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bhs.sansonglogistics.R;
import com.bhs.sansonglogistics.bean.CollaborationBean;
import com.bhs.sansonglogistics.bean.CollaborationInform;
import com.bhs.sansonglogistics.utils.MyUtils;
import com.bhs.sansonglogistics.utils.SharedPreferencesUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

public class CollaborationAdapter extends BaseQuickAdapter<CollaborationInform.DataDTO.ListDTO, BaseViewHolder> {

    private int type;
    private int logistics_id;

    public CollaborationAdapter(int type, int logistics_id) {
        super(R.layout.item_collaboration);
        this.type = type;
        this.logistics_id = logistics_id;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, CollaborationInform.DataDTO.ListDTO data) {
        CollaborationBean item = data.getShow_logistics_info();
        Glide.with(mContext).load(item.getCompany_pic()).into((ImageView) helper.getView(R.id.iv_image));
        helper.setText(R.id.tv_company_name, item.getCompany_name());
        if (data.getLine_info() != null) {
            String start_city = data.getLine_info().getStart_city().replace("市", "");
            helper.setText(R.id.tv_start_city, start_city);
            String end_city = data.getLine_info().getEnd_city().replace("市", "");
            helper.setText(R.id.tv_end_city, end_city);
            helper.setVisible(R.id.rl_line, data.getLine_info().getStart_city() != null);
        }

        helper.setText(R.id.tv_address, item.getAddress());
        // helper.setText(R.id.tv_distance, String.format("%skm", item.getDistance()));
        Spanned PageView = Html.fromHtml("浏览量:<font color=\"#000000\">" + item.getVisitor_count() + "</font>");
        helper.setText(R.id.tv_page_view, PageView);
        Spanned OrderQuantity = Html.fromHtml("下单量:<font color=\"#000000\">" + item.getOrder_count() + "</font>");
        helper.setText(R.id.tv_order_quantity, OrderQuantity);
        Spanned QuantityCollection = Html.fromHtml("收藏量:<font color=\"#000000\">" + item.getCollect_count() + "</font>");
        helper.setText(R.id.tv_quantity_collection, QuantityCollection);
        helper.setText(R.id.tv_announcement, item.getPublic_notice());
        helper.setGone(R.id.tv_announcement, !TextUtils.isEmpty(item.getPublic_notice()));
        helper.setText(R.id.tv_refuse, type == 1 ? "解除协作" : "拒绝");
        helper.setGone(R.id.tv_consent, type == 2 && logistics_id != data.getLogistics_id()&&data.getStatus() == 0);
        helper.setGone(R.id.ll_contact, false);
        helper.setGone(R.id.tv_refuse, (logistics_id != data.getLogistics_id() && data.getStatus() == 0) || type == 1);
        helper.addOnClickListener(R.id.tv_refuse).addOnClickListener(R.id.tv_consent);
        helper.setText(R.id.tv_hint, MyUtils.getStatusType(data.getStatus()));
        helper.setVisible(R.id.tv_hint, type == 2);

        //0 创建  1通过  2拒绝
    }
}
